package com.banshou.installs.model.net;

import com.banshou.installs.constant.Config;
import com.banshou.installs.utils.LoggerInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by cjq on 2018/1/2.
 * Email: stoic_yb@139.com
 * features:
 */

public class RetrofitManager {
    private Retrofit retrofit;
    private static RetrofitManager retrofitManager;

    private RetrofitManager(){
        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .addInterceptor(new LoggerInterceptor("HTTP",true))
                .build();
        retrofit = new Retrofit.Builder()
                .baseUrl(Config.BASEURL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public static RetrofitManager getInstance(){
        if(retrofitManager == null){
            synchronized (RetrofitManager.class){
                if(retrofitManager == null){
                    retrofitManager = new RetrofitManager();
                }
            }
        }
        return retrofitManager;
    }

    public <T>T create(Class<T> T){
        T t = retrofit.create(T);
        return t;
    }
}